package com.mvc.controller;
import com.alibaba.fastjson.JSON;
import com.mvc.entity.User;
import com.mvc.model.Result;
import com.mvc.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author king
 * @Date 2021/12/9 17:07
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/login", produces = "text/html;charset=UTF-8")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @RequestMapping(value = "/login.do")
    @ResponseBody
    public String listSearch(@RequestParam(required = false) Integer uid, @RequestParam(required = false) String upassword ){
        List<User> list = loginService.listSearch(uid,upassword);
        Result result = new Result();
        result.setCode(0);
        result.setData(list);
        String json = JSON.toJSONString(result);
        return json;
    }
    @RequestMapping(value = "/add.do")
    @ResponseBody
    public String add(User user){
        Integer n = loginService.insert(user);
        Result result = new Result();
        if (n == 1){
            result.setCode(0);
            result.setMsg("成功");
        }else {
            result.setCode(1);
            result.setMsg("失败");
        }
        String json = JSON.toJSONString(result);
        return json;
    }
}
